package com.feng.eduservice.controller;


import com.feng.commonutils.R;

import com.feng.eduservice.service.EduTeacherService;
import com.feng.eduservice.entity.EduTeacher;
import com.feng.eduservice.dto.TeacherQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author fengge
 * @since 2023-01-09
 */
@RestController
@RequestMapping("/eduservice/edu-teacher")
@Api(tags = "讲师管理")
@CrossOrigin
public class EduTeacherController {
    @Autowired
    private EduTeacherService eduTeacherService;
    //1.查询讲师所有数据
    @GetMapping("findAll")
    @ApiOperation("所有讲师列表")
    public R findAllTeacher(){

        return eduTeacherService.findAllTeacher();

    }
    //2.逻辑删除讲师的方法
    @ApiOperation(value = "根据ID删除讲师")
    @DeleteMapping("{id}")
    @CrossOrigin
    public R removeTeacher(@ApiParam(name = "id", value = "讲师ID", required = true) @PathVariable("id") String id){
          return eduTeacherService.removeTeacher(id);

    }
    //3.分页查询讲师的方法

    /**
     *
     * @param current 当前页
     * @param limit 每页展示数据
     * @return
     */
    @GetMapping("pageTeacher/{current}/{limit}")
    public R pageListTeacher(@PathVariable long current, @PathVariable long limit){
        return eduTeacherService.pageListTeacher(current,limit);
    }

    @PostMapping("pageTeacherCondition/{current}/{limit}")
    public R pageTeacherCondition(@PathVariable long current, @PathVariable long limit, @RequestBody(required = false) TeacherQuery teacherQuery){
        return eduTeacherService.pageTeacherCondition(current,limit,teacherQuery);


    }
    @PostMapping("addTeacher")
    public R addTeacher(@RequestBody EduTeacher eduTeacher){
        return eduTeacherService.addTeacher(eduTeacher);
    }
    //根据讲师id进行查询
    @GetMapping("getTeacher/{id}")
    public R getTeacher(@PathVariable String id){
        return eduTeacherService.getTeacher(id);
    }
    //根据讲师id修改讲师
    @PostMapping("updateTeacher")
    public R updateTeacher(@RequestBody EduTeacher eduTeacher){
        return  eduTeacherService.updateTeacher(eduTeacher);
    }


}

